<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Merchant extends MY_Controller {

	/**
	 * 用户假索引
	 * @var MerchantUserModel
	 */
	public $mMerchant;
	public function __construct(){
		parent::__construct();
        $this->loadModel('MerchantUserModel', 'mMerchant', 'merchant');
	}
	
	/**
	 * 首页
	 */
	public function index(){
		$data = array(
				'shopStatus'=>$this->_shopStatus(),
				'title'=>'商家管理',
		);
		
		$this->view('merchant/home', $data, 'datatable,select2,datepicker');
	}
	
	/**
	 * 增加
	 */
	public function add(){
		$data = array(
				'title'=>'商家管理',
				'add'=>1,
		);
		
		$this->view('merchant/form', $data, 'validation,fileinput,select2');
	}
	
	/**
	 * 详情
	 */
	public function details(){
        $this->loadModel('MerchantBalanceModel', 'mBalance', 'merchant');
        $this->loadModel('ConsumerCategoryModel', 'mCategory', 'consumer');
        $this->loadModel('MerchantAdsModel', 'mAds', 'merchant');
        $this->loadModel('ConsumerProductModel', 'mProduct', 'consumer');
        $this->loadModel('MerchantPromotionModel', 'mBonus', 'merchant');
        $this->loadModel('ConsumerOrderModel', 'mOrder', 'consumer');

        $id = (int)get('id');
        if (!$id) show_404();
		$tA = $this->mMerchant->getInfo($id);

		if ( ! $tA){
			show_404();
		}
		if (!in_array($tA['county'], $this->countyItem)){
		    show_error('没有访问权限');
        }
        //账户资金记录
        $found_status = $this->mBalance->config['status'];
        $found_type = $this->mBalance->config['type'];
        //周营业日
        $week = $this->mMerchant->config['week'];
        // 获取一级分类
        $catOne = $this->mCategory->getCategoryList(-1, true);
        //商家申请广告位置
        $position = getCustomConfig('merchant_position');
        //商家申请广告状态
        $adsStatus = $this->mAds->getStatus();
        //商家商品状态
        $proStatus = $this->mProduct->getStatus();
        $shopInfo = $this->mMerchant->getShopInfo($id);

		$data = array(
            'title' => '商家详情',
            'custom' => $this->mCategory->getCustomList($id),
            'info' => $tA,
            'found_status' => $found_status,
            'found_type' => $found_type,
            'week' => $week,
            'supervise' => $tA['supervise'],
            'catOne' => $catOne,
            'status' => $this->mOrder->status(),
            'position' => $position,
            'adsStatus' => $adsStatus,
            'proStatus' => $proStatus,
            'shopInfo' => $shopInfo,
            'cashInfo' => $this->mBonus->getCashInfo($id), //代金券
            'fullInfo' => $this->mBonus->getFullInfo($id) // 满减规则
		);
		
		$this->view('merchant/details', $data, 'datatable,validation,fileinput,select2,datepicker,uniform,timepicker');
	}
	
	/**
	 * 编辑
	 */
	public function edit(){

		$tA = $this->mMerchant->getInfo(get('id'), $this->countyItem);
		if ( ! $tA){
			show_404();
		}
        if (!in_array($tA['county'], $this->countyItem)){
            show_error('没有访问权限');
        }
		$data = array(
				'title'=>'商户列表',
				'add'=>0,
				'info'=>$tA,
		);
		$this->view('merchant/form', $data, 'validation,fileinput,select2');
	}
	
	/**
	 * 保存数据
	 */
	public function save(){

		//表单验证
		$vConf = array(
				array('mobile', '手机号码', 'required|valid_mobile'),
				array('gender', '性别', 'required|in_list[1,2,3]'),
				array('status', '状态', 'required|in_list[1,2]')
		);
		$this->formDataValidation($vConf);
		
		//获取
		$id = (int)post('id');
        $mobile = trim(post('mobile'));
		$password = trim(post('password'));
		$repassword = trim(post('repassword'));

        //验证手机号是否重复
        if($this->mMerchant->mobileIsExist($mobile, $id)){
            $this->ajaxReturn(0, '手机号码已经存在');
        }

        if($id){
            $info = $this->mMerchant->getInfo($id);
            if(!$info){
                $this->ajaxReturn(0, '商家不存在');
            }
            if (!in_array($info['county'], $this->countyItem)){
                $this->ajaxReturn(0, '没有访问权限');
            }
        }
		
		/**
		 * 数据
		 */
		$data = array(
				'mobile'	=> $mobile,
                'gender' => intval(post('gender')),
				'status'	=> (int)post('status'),
		);

		$this->db->trans_begin();//开启事务
		if (! $id){

            if(!$password) $this->ajaxReturn(0, '请设置登录密码');
            if(empty($_FILES['portrait'])) $this->ajaxReturn(0, '请上传商户头像');

            //新增数据 初始化
			$data['balance'] 			= 0;
			$data['min_consume']		= 0;
			$data['rank']		        = 1;//1初级 2中级 3高级
			$data['first_order_reduce']	= 0;//首单减免金额
			$data['able_use_coupon']	= 1;//不允许
			$data['able_cash_coupon']	= 1;//不允许
			$data['addtime']		= time();
			$data['jpush_code']	 	= uniqid().rand(1000, 9999).rand(100, 9999);//极光推送
			$data['password'] 		= setPassword($password);
			
			//保存
			$id = $this->mMerchant->save($data);
			if ( ! $id){
				$this->db->trans_rollback();//回滚
				$this->ajaxReturn(0,'保存失败');
			}

            //注册环信账号
            $result = easemob($easemobName = $data['jpush_code'], $easemobword = $mobile.$id );

            if($result['status'] == 0){
                $this->db->trans_rollback();
                $this->appReturn(0,'注册失败:'.$result['error']);
            }
		}

        if ($id && $password){
            if ($password != $repassword){
                $this->ajaxReturn(0,'密码不一致');
            }

            $data['password'] = setPassword($password);
        }

		if (isset($_FILES['portrait'])){
			//上传头像
			$path = 'uploads/merchant/'.$id.'/portrait';

			$tA = imageUpload($path,'portrait','portrait', true, 250, 250);
			if( ! $tA['status']){
				##图片路径
				$this->db->trans_rollback();//回滚
				$this->ajaxReturn(0, '头像上传失败');
			}
            $data['portrait'] = $tA['data'];
		}

        $query = $this->mMerchant->save($data,$id);
        if ( ! $query){
            $this->db->trans_rollback();//回滚
            $this->ajaxReturn(0,'保存失败');
        }
		$this->db->trans_commit();
		$this->ajaxReturn(1, '保存成功', null, getUrl('merchant'));
	}
	
	/**
	 * 获取列表
	 */
	public function getList(){
		$data = $this->mMerchant->adminGetList($this->countyItem);
		foreach ($data['data'] as $k=>$v){
		    $img = isset($v['portrait']) ? getImage($v['portrait'],'xs') : getDefaultPortrait(2);
			$data['aaData'][$k][] = '<img src="'.$img.'" class="img-wh"/>';
			$data['aaData'][$k][] = $v['shop_name'];
			$data['aaData'][$k][] = $v['mobile'];
			$data['aaData'][$k][] = $v['balance'];
			$data['aaData'][$k][] = isset($v['percent']) ? $v['percent'] : '暂无';
			$data['aaData'][$k][] = isset($v['score']) ? $v['score']: '暂无';
			$data['aaData'][$k][] = date('Y-m-d H:i:s',$v['addtime']);
			$data['aaData'][$k][] = isset($v['shop_addtime']) ? date('Y-m-d H:i:s',$v['shop_addtime']) : '暂无';
            $status = $v['status'] == 1 ? 2 : 1;
            $data['aaData'][$k][] = "<a href='".getUrl('merchant/status?id=').$v['id'].'&status='.$status.
                "' class='ajax-request-btn deco' alert-message='是否确认".$this->adminStatus($status)."'>".$this->adminStatus($v['status'],true)."</a>";

			$data['aaData'][$k][] = isset($v['shop_status']) ? $this->_shopStatus($v['shop_status'],1):'暂无认证';

			$btnConfig = adminCreateBtn(array(
							'label' => '详情',
							'attr' => array(
									'href' => getUrl('merchant/details?id='.$v['id']),
									'class' => 'btn btn-xs green-stripe default'
							),
							'tag' => 'a'
					));
            //编辑
            $btnConfig .= ' '.adminCreateBtn(array(
                    'label' => '编辑',
                    'attr' => array(
                        'href' => getUrl('merchant/edit?id='.$v['id']),
                        'class' => 'btn btn-xs blue-stripe default edit-btn'
                    ),
                    'tag' => 'a',
                ));
			//认证按钮
			if(isset($v['shop_status']) && $v['shop_status'] == 3){
					
					$btnConfig .= ' '.adminCreateBtn(array(
							'label' => '认证通过',
							'attr' => array(
									'href' => getUrl('merchant/shopStatus?id='.$v['id'].'&status=2'),
									'class' => 'ajax-request-btn btn btn-xs blue-stripe default',
									'alert-message'=>'确定要通过“'.$v['nickname'].'”的认证?',
							),
							'tag' => 'a',
					));
					$btnConfig .=' '.adminCreateBtn(array(
							'label' => '拒绝认证',
							'attr' => array(
									'href' => getUrl('merchant/shopStatus?id='.$v['id'].'&status=1'),
									'class' => 'ajax-request-btn btn btn-xs red-stripe default',
									'alert-message'=>'确定要拒绝“'.$v['nickname'].'”的认证?',
							),
							'tag' => 'a',
					));
			}


			$data['aaData'][$k][] = $btnConfig;
		}
		
		unset($data['data']);
		echo json_encode($data);
	}

    /**
     * 商家升级
     */
    public function upgrade(){
        $this->ajaxReturn(1, '升级成功', '5');
        //表单验证
        $vConf = array(
            array('id', 'id', 'required|is_natural_no_zero')
        );
        $this->formDataValidation($vConf, array('id' => get('id')));
        $this->loadModel('MerchantUserModel', 'mMer','merchant');
        $id = (int)get('id');
        $info = $this->mMerchant->getInfo($id, 0, true);
        if (empty($info)){
            $this->ajaxReturn(0, '商家不存在');
        }
        if ($info['rank'] != 1 && $info['rank'] != 2){
            $this->ajaxReturn(0, '该商家不能升级');
        }
        $rank = $info['rank']+1;
        $this->db->trans_begin();
        $tA = $this->mMerchant->save(array('rank' => $rank), $id);
        if (!$tA){
            $this->db->trans_rollback();
            $this->ajaxReturn(0, '升级失败');
        }
        // 添加升级记录
        $data = array(
            'merchant_id' => $id,
            'rank' => $rank,
            'addtime' => time()
        );
        $rS = $this->mMerchant->saveRankLog($data);
        if (!$rS){
            $this->db->trans_rollback();
            $this->ajaxReturn(0, '升级失败');
        }
        $this->db->trans_commit();
        $this->ajaxReturn(1, '升级成功', array('data' => 'upgrade',
            'rank_name' => $this->mMerchant->config['rank'][$rank],
            'rank' => $rank
        ));
    }

    /**
     * 保存店铺信息
     */
    public function saveStore(){
        //表单验证
        $vConf = array(
            array('shop_name', '店铺名称', 'required'),
            array('store_tel', '店铺电话', 'required'),
            array('merchant_id', '商户id', 'required|is_numeric'),
            array('min_consume', '起送价格', 'required|is_numeric'),
            array('first_order_reduce', '首单减免金额', 'required|is_numeric'),
            array('able_use_coupon', '是否支持使用红包', 'required|in_list[1,2]'),
            array('able_cash_coupon', '是否启用代金券', 'required|in_list[1,2]'),
            array('percent', '平台比例', 'required'),
            array('business', '营业状态', 'required|in_list[1,2]')
        );
        $this->formDataValidation($vConf);

        $merchant_id = intval(post('merchant_id'));
        $start = trim(post('business_time_start'));
        $end = trim(post('business_time_end'));
        $week = post('week');
        $percent = trim(post('percent'));
        if ($percent < 0){
            $this->ajaxReturn(0, '平台比例不得小于零');
        }

        if(!$week){
            $this->ajaxReturn(0, '请选择周营业日');
        }

        if(!is_int(strtotime($start)) || !is_int(strtotime($end))){
            $this->ajaxReturn(0, '时间格式错误');
        }

        //验证商户
        $info = $this->mMerchant->getInfo($merchant_id);
        if(!$info){
            $this->ajaxReturn(0, '商户不存在');
        }

        $data = array(
            'store_tel' => trim(post('store_tel')),
            'min_consume' => post('min_consume'),
            'first_order_reduce' => post('first_order_reduce'),
            'able_use_coupon' => (int)post('able_use_coupon'),
            'able_cash_coupon' => (int)post('able_cash_coupon'),
            'business' => (int)post('business'),
            'percent' => $percent,
            'business_time_start' => time_to_second($start),
            'business_time_end' => time_to_second($end),
            'business_week' => ','.implode(',',$week).','
        );

        //保存信息
        if(!($this->mMerchant->save($data, $merchant_id))){
            $this->ajaxReturn(0, '保存失败');
        }
        if(!($this->mMerchant->saveShop(array('shop_name' => trim(post('shop_name'))), $merchant_id))){
            $this->ajaxReturn(0, '保存失败');
        }
        $this->ajaxReturn(1, '保存成功');
    }

	/**
	 * 获取状态显示样式
	 * @param 	integer $status
	 * @param 	bool    $show
	 * @return	string
	 */
	private function _shopStatus($status = null, $show = false){
		
		$config = array(1 => '认证失败', 2 => '认证成功', 3 =>'审核中');
		if( ! $status){
			return $config;
		}
		
		if($status && ! isset($config[$status])){
			return '';
		}
		
		if( ! $show){
			return $config[$status];
		}
		
		
		if($status == 1){
			return '<span class="label label-danger">'.$config[$status].'</span>';
		}else if($status == 2){
			return '<span class="label label-success">'.$config[$status].'</span>';
		}else if($status == 3){
			return '<span class="label label-warning">'.$config[$status].'</span>';
		}
		
		return'';
	}
	
	/**
	 * 更改状态
	 */
	public function status(){
		
		$id = get('id');
		$status = get('status');
		if (! $id || ! $status || ! in_array($status, array(1,2))){
			$this->ajaxReturn(0,'参数错误');
		}
		
		$this->loadModel('MerchantUserModel', 'mMer','merchant');
		if( ! $this->mMer->save(array('status'=>$status),$id)){
			$this->ajaxReturn(0,'保存失败');
		}
		$this->ajaxReturn(1,'保存成功');
	}
	
	/**
	 * 更改认证状态
	 */
	public function shopStatus(){
		$id = get('id');
		$status = get('status');
		if (! $id || ! $status || ! in_array($status, array(1,2))){
			$this->ajaxReturn(0,'参数错误');
		}
		
		$this->loadModel('MerchantUserModel', 'mMer','merchant');
		if( ! $this->mMer->saveShop(array('status'=>$status),$id)){
			$this->ajaxReturn(0,'保存失败');
		}
		$this->ajaxReturn(1,'保存成功');
	}

/*********************************************订单管理*****************************************************************/

    /**
     * 订单列表
     */
    public function orderList(){
        $this->loadModel('ConsumerOrderModel', 'mOrder', 'consumer');
        $id = (int)get('merchant_id');
        $data = $this->mOrder->adminPcGetOrderList($id);
        if ($data['data']){
            foreach ($data['data'] as $k => $v){
                $data['aaData'][$k][] = $v['code'];
                $data['aaData'][$k][] = $v['consumer'];
                $data['aaData'][$k][] = $this->mOrder->expenseType($v['expense_type']);
                $data['aaData'][$k][] = $v['total_amount'];
                $data['aaData'][$k][] = $v['reality_amount'];
                $data['aaData'][$k][] = $this->mOrder->payType($v['pay_type']);
                $data['aaData'][$k][] = dateFormat($v['addtime']);
                $data['aaData'][$k][] = $this->mOrder->status($v['status'], true);

                $btnConfig = adminCreateBtn(array(
                    'label' => '查看',
                    'attr' => array(
                        'href' => getUrl('member/merchant/orderDetails?id='.$v['id']),
                        'class' => 'btn green-stripe btn-xs default'
                    ),
                    'tag' => 'a',
                ));
                if ($v['status'] == 7){
                    $btnConfig .=' '.adminCreateBtn(array(
                            'label' => '删除',
                            'attr' => array(
                                'href' => getUrl('order/home/deleteOrder?id='.$v['id']),
                                'class' => 'btn btn-xs red-stripe default ajax-request-btn',
                                'alert-message' => '是否确认删除订单？'
                            ),
                            'tag' => 'a',
                        ));
                }
                $data['aaData'][$k][] = $btnConfig;
            }
        }
        unset($data['data']);
        echo json_encode($data);
    }

    /**
     * 订单详情
     */
    public function orderDetails(){
        $id = get('id');
        if( ! is_numeric($id)){
            show_404();
        }
        $this->loadModel('AdmSettingModel', 'mAdm', 'admin');
        $this->loadModel('AdmShippingModel', 'mShipping', 'admin');
        $this->loadModel('ConsumerOrderModel', 'mOrder', 'consumer');

        $info = $this->mOrder->getInfo($id);  // 订单信息
        if (empty($info)){
            show_404();
        }
        $oP = $this->mOrder->getOrderProductInfoByIds(array(), $id); // 订单商品信息
        if ($info['expense_type'] == 2){
            $buttons = $this->mOrder->storeStatus($info['status'], false, true, false); // 操作按钮
        }else{
            $buttons = $this->mOrder->status($info['status'], false, true, false); // 操作按钮
        }
        $province = $this->mAdm->getLocationByPid(1);  // 获取省份
        $ship = $this->mShipping->getList();    // 获取快递公司
        $requestData = [
            "OrderCode"=>$info['code'],
            "ShipperCode"=>$info['express_param']['express_code'],
            "LogisticCode"=>$info['express_param']['express_bill']
        ];
        $kd = KDNiao()->getOrderTracesByJson($requestData);  // 查看物流信息
        $data = array(
            'info' => $info,
            'oP' => empty($oP) ? array() : $oP[$id],
            'buttons' => $buttons,
            'province' => $province,
            'ship' => $ship,
            'kd' => json_decode($kd, true),
            'backUrl' => getUrl('member/merchant/details?id='.$info['merchant_id']),
            'title' => '订单详情'
        );
        $this->view('order/details', $data, 'datatable,validation,region,select2');
    }

/*********************************************售后订单*****************************************************************/

    /**
     * 获取售后列表
     */
    public function serviceList(){
        $this->loadModel('ConsumerOrderModel', 'mOrder', 'consumer');
        $merchant_id = (int)get('merchant_id');
        $data = $this->mOrder->adminPcGetOrderServiceList($merchant_id);
        if ($data['data']){
            foreach ($data['data'] as $k => $v){
                $data['aaData'][$k][] = $v['code'];
                $data['aaData'][$k][] = $v['order_code'];
                $data['aaData'][$k][] = $v['name'];
                $data['aaData'][$k][] = $v['remark'];
                $data['aaData'][$k][] = $v['refund_amount'];
                $data['aaData'][$k][] = dateFormat($v['addtime']);
                $data['aaData'][$k][] = $this->mOrder->serviceType($v['status'], true);
                $btnConfig = adminCreateBtn(array(
                    'label' => '查看',
                    'attr' => array(
                        'href' => getUrl('member/merchant/serviceDetails?code='.$v['code']),
                        'class' => 'btn green-stripe btn-xs default'
                    ),
                    'tag' => 'a'
                ));
                $data['aaData'][$k][] = $btnConfig;
            }
        }
        unset($data['data']);
        echo json_encode($data);
    }

    /**
     * 查看售后订单
     */
    public function serviceDetails(){
        $code = get('code');
        $this->loadModel('ConsumerOrderModel', 'mOrder', 'consumer');
        $serviceInfo = $this->mOrder->getServiceInfo($code);  // 售后信息
        if (empty($serviceInfo)){
            show_404();
        }
        $info = $this->mOrder->getInfo($serviceInfo['order_id']);  // 订单信息
        $oP = $this->mOrder->getOrderProductInfoByIds($serviceInfo['order_product_id'], $serviceInfo['order_id']); // 订单商品信息

        $data = array(
            'info' => $info,
            'serviceInfo' => $serviceInfo,
            'oP' => empty($oP) ? array() : $oP[$serviceInfo['order_product_id']],
            'backUrl' => getUrl('member/merchant/details?id='.$serviceInfo['merchant_id']),
            'title' => '售后详情'
        );
        $this->view('order/service/details', $data, 'datatable,validation,region,select2');
    }

/*********************************************评价列表*****************************************************************/

    /**
     * 评价列表
     */
    public function getCommentList(){
        $iSortCol_0 = (int)get('iSortCol_0');
        if ($iSortCol_0 > 0){
            $_GET['iSortCol_0'] = $iSortCol_0 + 1;
        }
        $merchantId = (int)get('merchant_id');
        $this->loadModel('MerchantCommentModel', 'mComment', 'merchant');
        $data = $this->mComment->adminGetList($merchantId);
        foreach ($data['data'] as $k=>$v){
            $data['aaData'][$k][] = $v['name'];
            $data['aaData'][$k][] = '<textarea readonly class="form-control remaks-item content textarea_height" style="height: 36px;">'.$v['content'].'</textarea>';
            $data['aaData'][$k][] = $v['score'];
            $data['aaData'][$k][] = $v['c_name'];
            // 商家回复
            if (!empty($v['reply'])){
                $data['aaData'][$k][] = '<a href="#" class="popovers" data-placement="left" data-trigger="hover" data-content="'
                    .$v['reply'].'" data-original-title="商家回复">[商家回复]</a>';
            }else{
                $data['aaData'][$k][] = '';
            }
            // 平台回复
            if (!empty($v['admin_reply'])){
                $data['aaData'][$k][] = '<a href="#" class="popovers" data-placement="left" data-trigger="hover" data-content="'
                    .$v['admin_reply'].'" data-original-title="平台回复">[平台回复]</a>';
            }else{
                $data['aaData'][$k][] = '';
            }

            $data['aaData'][$k][] = date('Y-m-d H:i:s',$v['addtime']);
            $btnConfig = adminCreateBtn(array(
                'label' => '图片',
                'attr' => array(
                    'href' => 'javascript:;',
                    'class' => 'btn btn-xs green-stripe default img-btn',
                    'data-id' => $v['id'],
                ),
                'tag' => 'a'
            ));
            if (empty($v['admin_reply'])){
                $btnConfig .=' '.adminCreateBtn(array(
                        'label' => '回复',
                        'attr' => array(
                            'href' => 'javascript:void(0)',
                            'class' => 'reply btn btn-xs blue-stripe default',
                            'data-id'=>$v['id'],
                        ),
                        'tag' => 'a'
                    ));
            }
            $btnConfig .=' '.adminCreateBtn(array(
                    'label' => '删除',
                    'attr' => array(
                        'href' => getUrl('product/comment/rmComment?id='.$v['id']),
                        'class' => 'btn btn-xs red-stripe default ajax-request-btn',
                        'alert-message'=>'确定要删除 “ '.$v['c_name'].' ” 的评价?',
                    ),
                    'tag' => 'a'
                ));
            $data['aaData'][$k][] = $btnConfig;
        }

        unset($data['data']);
        echo json_encode($data);
    }

/*********************************************监管信息*****************************************************************/

    /**
     * 获取监管信息
     * @author heyu
     */
    public function getSuperviseList(){
        $tA = $this->mMerchant->getInfo(get('id'));
        echo json_encode($tA['supervise']);
    }

	/**
     * 保存监管信息
     * ------------------------------------------------------------------------------------------------------------------
     */
	public function saveSupervise(){
        //表单验证
        $vConf = array(
            array('merchant_id', '商家id', 'required|is_numeric'),
            array('supervise', '监管局', 'required'),
            array('supervise_department', '监管部门', 'required'),
            array('supervise_name', '监管人', 'required'),
            array('supervise_tel', '监管人电话', 'required')
        );
        $this->formDataValidation($vConf);

        $merchantId = (int)post('merchant_id');
        $id = post('id');
        $info = $this->mMerchant->getInfo($merchantId, 0, true);
        if(!$id && !$info && !isset($_FILES['supervise_man_portrait']) && !isset($_FILES['supervise_woman_portrait'])){
            $this->ajaxReturn(0, '请上传头像');
        }

        $data = array(
            'supervise' => trim(post('supervise')),
            'supervise_department' => trim(post('supervise_department')),
            'supervise_name' => trim(post('supervise_name')),
            'supervise_tel' => trim(post('supervise_tel')),
            'supervise_man_portrait' => '',
            'supervise_woman_portrait' => '',
        );
        //上传监督头像
        $array=array('supervise_man_portrait','supervise_woman_portrait');
        foreach ($_FILES as $k=>$v){
            if(in_array($k,$array)){
                $path = 'uploads/member/supervise/'.$merchantId;

                $tA = imageUpload($path,$k,uniqid(),false);

                if( ! $tA['status']){
                    $this->ajaxReturn(0, '头像上传失败');
                }
                $data[$k] = $tA['data'];
            }
        }
        $man = ''; $woman = '';
        if (is_numeric($id) && (int)$id > -1){
            if (empty($data['supervise_man_portrait'])){
                $data['supervise_man_portrait'] = $info['supervise'][$id]['supervise_man_portrait'];
            }else{
                $man = $info['supervise'][$id]['supervise_man_portrait'];
                $mArr = explode('?', $man);
                $man = $mArr[0];
            }
            if (empty($data['supervise_woman_portrait'])){

                $data['supervise_man_portrait'] = $info['supervise'][$id]['supervise_woman_portrait'];
            }else{
                $woman = $info['supervise'][$id]['supervise_woman_portrait'];
                $wArr = explode(',', $woman);
                $woman = $wArr[0];
            }
            $info['supervise'][$id] = $data;
        }else{
            $info['supervise'][] = $data;
        }
        //保存信息
        if(($this->mMerchant->save(array('supervise' => json_encode($info['supervise'])), $merchantId)) === false){
            $this->ajaxReturn(0, '保存失败');
        }
        if ($man){
            @unlink($man);
        }
        if ($woman){
            @unlink($woman);
        }
        $this->ajaxReturn(1, '保存成功', 'supervise');
    }

    /**
     * 删除监管信息
     * @author heyu
     */
    public function deleteSupervise(){
        $merchantId = (int)get('merchant_id');
        $id = get('id');
        $info = $this->mMerchant->getInfo($merchantId, 0, true);
        if (!$info){
            $this->ajaxReturn(0, '数据不存在');
        }

        if (!is_numeric($id) || (int)$id < 0){
            $this->ajaxReturn(0, '数据错误');
        }

        $superviseMan = $info['supervise'][$id]['supervise_man_portrait'];
        $superviseWoman = $info['supervise'][$id]['supervise_woman_portrait'];
        if (strpos($superviseMan, '?')){
            $mArr = explode('?', $superviseMan);
            $superviseMan = $mArr[0];
        }
        if (strpos($superviseWoman, '?')){
            $wArr = explode('?', $superviseWoman);
            $superviseWoman = $wArr[0];
        }

        @unlink($superviseMan);
        @unlink($superviseWoman);
        unset($info['supervise'][$id]);
        $data = array();
        foreach ($info['supervise'] as $v){
            $data[] = $v;
        }
        $info['supervise'] = $data;
        //保存信息
        if(($this->mMerchant->save(array('supervise' => json_encode($info['supervise'])), $merchantId)) === false){
            $this->ajaxReturn(0, '删除失败');
        }
        $this->ajaxReturn(1, '删除成功', 'supervise');
    }

    /**
  * 银行卡（支付宝）
  * ————————————————————————————————————————————————————————
  */
    public function bankCardList(){

        $this->loadModel('MerchantBankModel', 'mBank', 'merchant');

        $data = $this->mBank->adminGetList();
        if($data){

            foreach ($data['data'] as $key=>$value){
                $data['aaData'][$key][] = $this->mBank->getBankType($value['type']);
                $data['aaData'][$key][] = $value['account_name'];
                $data['aaData'][$key][] = $value['account_number'];
                $data['aaData'][$key][] = $value['open_bank'];
                $data['aaData'][$key][] = $value['mobile'];
                $data['aaData'][$key][] =  '';
            }
        }

        unset($data['data']);
        echo json_encode($data);
    }

/*********************************************资金明细*****************************************************************/

    /**
     * 资金明细
     * ————————————————————————————————————————————————————————
     */
    public function FoundLogList(){
        $this->loadModel('MerchantBalanceModel', 'mBalance', 'merchant');

        $data = $this->mBalance->adminGetList();

        if($data){

            foreach ($data['data'] as $key=>$value){
                $data['aaData'][$key][] = $this->mBalance->config['type'][$value['type']];
                $data['aaData'][$key][] = $value['amount'];
                $data['aaData'][$key][] = $this->mBalance->config['status'][$value['status']];
                $data['aaData'][$key][] = dateFormat($value['addtime'],true);
                $data['aaData'][$key][] =  '';
            }
        }

        unset($data['data']);
        echo json_encode($data);
    }

    /**
     * 保存资金记录
     */
    public function saveFound(){
        $this->loadModel('MerchantBalanceModel', 'mBalance', 'merchant');
        //表单验证
        $vConf = array(
            array('merchant_id', '商户id', 'required|is_numeric'),
            array('amount', '金额', 'required|is_numeric'),
            array('type', '变动类型', 'required|in_list[1,2]')
        );
        $this->formDataValidation($vConf);

        $merchant_id = intval(post('merchant_id'));
        $type = intval(post('type'));//1 增加 2减少
        $amount = post('amount');
        if ($amount <= 0){
            $this->ajaxReturn(0, '调整金额必须大于零');
        }

        //验证商户
        $info = $this->mMerchant->getInfo($merchant_id);
        if(!$info){
            $this->ajaxReturn(0, '商户不存在');
        }
        if ($type == 2 && $info['balance'] < $amount){
            $this->ajaxReturn(0, '最大减少金额为'.$info['balance']);
        }
        $data = array(
            'merchant_id' => $merchant_id,
            'status' => 2,
            'type' => 7,
            'pay_type' => 5,
            'addtime' => time(),
            'confirm_time' => time()
        );

        $merchant_balance = $info['balance'];
        if($type == 1){//增加
            $data['amount'] = $amount;
            $merchant_balance += $amount;
        }else{//减少
            $data['amount'] = '-'.$amount;
            $merchant_balance -= $amount;
        }

        //保存记录
        $this->db->trans_begin();
        if(!($this->mBalance->save($data))){
            $this->db->trans_rollback();
            $this->ajaxReturn(0, '保存失败');
        }
        unset($data);

        //更新商户账号余额
        if(!($this->mMerchant->save(array('balance' => $merchant_balance), $merchant_id))){
            $this->db->trans_rollback();
            $this->ajaxReturn(0, '保存失败');
        }

        $this->db->trans_commit();
        $this->ajaxReturn(1, '保存成功',array('balance' => $merchant_balance));
    }

/*********************************************红包投放*****************************************************************/

    /**
    * 红包投放记录
    * ————————————————————————————————————————————————————————
    */
    public function bonusList(){
        $this->loadModel('MerchantPromotionModel', 'mBonus', 'merchant');

        $data = $this->mBonus->adminGetList();

        if($data){

            foreach ($data['data'] as $key=>$value){
                $data['aaData'][$key][] = '<div style="width:100%;height:100%;position:relative;">
									     <img class="pic img-wh"  width="100%;"  src="'.getImage($value['pic'],'og').'" alt=""></div>';
                $data['aaData'][$key][] = '开始时间：'.dateFormat($value['start_time']).' 结束时间：'.dateFormat($value['end_time']);
                $data['aaData'][$key][] = $value['amount'];
                $data['aaData'][$key][] = $value['number'];
                $data['aaData'][$key][] = $value['receive_number'];
                $data['aaData'][$key][] = $this->_bonusStatus($value['status']);
                $btnConfig = '';
                if($value['status'] == 2){//未开始
                    //编辑
                    $btnConfig = adminCreateBtn(array(
                            'label' => '编辑',
                            'attr' => array(
                                'href' => getUrl('merchant/bonusInfo?id='.$value['id'].'&merchant_id='.$value['merchant_id']),
                                'class' => 'btn btn-xs blue-stripe default edit-btn'
                            ),
                            'tag' => 'a'
                        ));

                }

                if($value['status'] == 3){//进行中
                    $btnConfig = adminCreateBtn(array(
                        'label' => '立即结束',
                        'attr' => array(
                            'href' => getUrl('merchant/changeBonusStatus?id='.$value['id'].'&merchant_id='.$value['merchant_id']),
                            'class' => 'btn btn-xs red-stripe default ajax-request-btn',
                            'alert-message' => '确认是否结束活动？'
                        ),
                        'tag' => 'a',
                    ));
                }
                $data['aaData'][$key][] =  $btnConfig;
            }
        }

        unset($data['data']);
        echo json_encode($data);
    }

    /**
     * 红包信息
     */
    public function bonusInfo(){
        $this->loadModel('MerchantPromotionModel', 'mBonus', 'merchant');

        $merchant_id = intval(get('merchant_id'));
        $id = intval(get('id'));

        if(!$merchant_id || !$id){
            $this->ajaxReturn(0, '红包不存在');
        }
        //获取红包信息
        $info = $this->mBonus->getBonusInfo($id, $merchant_id);
        if(!$info){
            $this->ajaxReturn(0, '红包不存在');
        }

        echo json_encode($info);
    }

    /**
     * 保存红包信息（图片，状态）
     */
    public function saveBonus(){
        $this->loadModel('MerchantPromotionModel', 'mBonus', 'merchant');

        //表单验证
        $vConf = array(
            array('merchant_id', '商户id', 'required|is_numeric'),
        );
        $this->formDataValidation($vConf);

        $merchant_id = (int)post('merchant_id');
        $id = (int)post('id');
        $startTime = trim(post('start_time'));
        $endTime = trim(post('end_time'));
        $startTime = strtotime($startTime);
        $endTime = strtotime($endTime);

        if(!is_int($startTime) || !is_int($endTime)){
            $this->ajaxReturn(0, '时间格式错误');
        }
        if ($endTime < $startTime){
            $this->ajaxReturn(0, '结束时间必须大于开始时间');
        }
        $time = strtotime(date('Y-m-d',time()));
        if ($endTime < $time){
            $this->ajaxReturn(0, '结束时间必须大于当天时间');
        }
        $status = 0;
        if ($startTime < $time){
            $status = 3;
        }
        //获取红包信息
        $info = $this->mBonus->getBonusInfo($id, $merchant_id);
        if(!$info){
            $this->ajaxReturn(0, '红包不存在');
        }

        if($info['status'] != 2){
            $this->ajaxReturn(0, $info['status'].'只有未开始的活动才可以编辑');
        }

        $data = array(
            'merchant_id' => $merchant_id,
            'start_time' => $startTime,
            'end_time' => $endTime,
        );
        if ($status){
            $data['status'] = $status;
        }
        if (isset($_FILES['pic'])){
//            p($_FILES);
            //上传广告图
            $path = 'uploads/merchant/'.$id.'/bonus';
            $tA = imageUpload($path,'pic','pic'.$id, true, 250, 250);

            if( ! $tA['status']){
                $this->ajaxReturn(0, '广告图上传失败');
            }
            $data['pic'] = $tA['data'];
        }
        $rS = $this->mBonus->save($data, $id);
        if (!$rS){
            $this->ajaxReturn(0, '保存失败');
        }
        $this->ajaxReturn(1, '保存成功', 'bonus');
    }

    /**
     * 立即结束
     */
    public function changeBonusStatus(){
        $this->loadModel('MerchantPromotionModel', 'mBonus', 'merchant');
        //表单验证
        $vConf = array(
            array('merchant_id', '商户id', 'required|is_numeric'),
            array('id', 'id', 'required|is_numeric')
        );
        $this->formDataValidation($vConf, array('merchant_id' => get('merchant_id'), 'id' => get('id')));

        $merchant_id = (int)get('merchant_id');
        $id = (int)get('id');

        //获取红包信息
        $info = $this->mBonus->getBonusInfo($id, $merchant_id);
        if(!$info){
            $this->ajaxReturn(0, '红包不存在');
        }

        //获取红包信息
        $info = $this->mBonus->save(array('status' => 1), $id);
        if(!$info){
            $this->ajaxReturn(0, '保存失败');
        }
        $this->ajaxReturn(1, '保存成功', 'bonus');
    }

/*********************************************代金券投放***************************************************************/

    /**
     * 保存数据
     * @author heyu
     */
    public function saveCoupon(){
        //表单验证
        $vConf = array(
            array('merchant_id', '用户id', 'required|is_numeric'),
            array('money', '券面额', 'required'),
            array('valid_hour', '券有效时间', 'required|is_numeric'),
            array('receive', '获得条件', 'required'),
            array('condition', '使用条件', 'required'),
        );
        $this->formDataValidation($vConf);
        $this->loadModel('MerchantPromotionModel', 'mBonus', 'merchant');

        $id = intval(post('merchant_id'));

        // 查看代金券信息
        $info = $this->mBonus->getCashInfo($id);

        $data = array(
            'merchant_id' => $id,
            'money' => trim(post('money')),
            'valid_hour' => trim(post('valid_hour')),
            'receive' => trim(post('receive')),
            'condition' => trim(post('condition')),
        );
        if (!$info){
            $data['addtime'] = time();
        }

        //保存信息
        if(!($this->mBonus->saveCash($data, $id))){
            $this->ajaxReturn(0, '保存失败');
        }
        $this->ajaxReturn(1, '保存成功');
    }


    /*********************************************满减规则*****************************************************************/

    /**
     * 保存满减规则
     */
    public function saveFull(){
        //表单验证
        $vConf = array(
            array('merchant_id', '用户id', 'required|is_numeric'),
            array('start_time', '券面额', 'required'),
            array('end_time', '券面额', 'required'),
        );
        $this->formDataValidation($vConf);
        $this->loadModel('MerchantPromotionModel', 'mBonus', 'merchant');

        $id = intval(post('merchant_id'));
        $rule = post('rule');
        $start_time = trim(post('start_time'));
        $end_time = trim(post('end_time'));
        $start_time = strtotime($start_time);
        $end_time = strtotime($end_time);
        if (!$start_time){
            $this->ajaxReturn(0, '请选择正确的起始时间');
        }
        if (!$end_time){
            $this->ajaxReturn(0, '请选择正确的结束时间');
        }
        if ($start_time > $end_time){
            $this->ajaxReturn(0, '起始时间不得大于结束时间');
        }

        // 查看代金券信息
        $info = $this->mBonus->getFullInfo($id);

        $data = array(
            'merchant_id' => $id,
            'start_time' => $start_time,
            'end_time' => $end_time,
            'rule' => json_encode($rule, JSON_UNESCAPED_UNICODE),
        );
        if (!$info){
            $data['addtime'] = time();
        }

        //保存信息
        if(!($this->mBonus->saveFull($data, $id))){
            $this->ajaxReturn(0, '保存失败');
        }
        $this->ajaxReturn(1, '保存成功');
    }

/*********************************************商品分类*****************************************************************/

    /**
     * 商品分类
     * @author heyu
     */
    public function getCategoryList(){
        $this->loadModel('ConsumerCategoryModel', 'mCategory', 'consumer');
        $data = $this->mCategory->adminGetCustomCategoryListByMerchantId();
        if($data){
            foreach ($data['data'] as $key=>$v){
                $data['aaData'][$key][] = $v['id'];
                $data['aaData'][$key][] = $v['parent_name'];
                $data['aaData'][$key][] = $v['category_name'];
                $data['aaData'][$key][] = $v['cat_name'];
                $status = $v['status'] == 1 ? 2 : 1;
                $data['aaData'][$key][] = "<a href='".getUrl('merchant/changeCategoryStatus').'?id='.$v['id'].
                    "' class='ajax-request-btn deco' alert-message='是否确认".$this->adminStatus($status)."'>".$this->adminStatus($v['status'],true)."</a>";
                $data['aaData'][$key][] = dateFormat($v['addtime']);

                $btnConfig = adminCreateBtn(array(
                        'label' => '编辑',
                        'attr' => array(
                            'href' => getUrl('product/category/getCustomInfo?id='.$v['id']),
                            'class' => 'btn btn-xs blue-stripe default category-edit-btn'
                        ),
                        'tag' => 'a'
                    ));
                $btnConfig .= ' '.adminCreateBtn(array(
                        'label' => '删除',
                        'attr' => array(
                            'href' => getUrl('product/category/deleteCustomCategory').'?id='.$v['id'],
                            'class' => 'btn btn-xs red-stripe default ajax-request-btn',
                            'alert-message' => '是否确认删除分类？'
                        ),
                        'tag' => 'a',
                    ));
                $data['aaData'][$key][] =  $btnConfig;
            }
        }
        unset($data['data']);
        echo json_encode($data);
    }

    /**
     * 获取二级分类
     * @author heyu
     */
    public function getCategoryTwo(){
        //表单验证
        $vConf = array(
            array('id', 'id', 'required|is_natural_no_zero'),
        );
        $this->formDataValidation($vConf);
        $this->loadModel('ConsumerCategoryModel', 'mCategory', 'consumer');
        $id = (int)post('id');
        $data = $this->mCategory->getCategoryList($id, true);
        if (empty($data)){
            $this->ajaxReturn(0, '无数据,请选择其他分类');
        }
        $this->ajaxReturn(1, '', $data);
    }

    /**
     * 商品修改状态
     * @author heyu
     */
    public function changeCategoryStatus(){
        //表单验证
        $vConf = array(
            array('id', 'id', 'required|is_natural_no_zero'),
        );
        $this->formDataValidation($vConf, array('id' => get('id')));
        $this->loadModel('ConsumerCategoryModel', 'mCategory', 'consumer');
        $id = (int)get('id');
        $info = $this->mCategory->getCustomInfo($id);
        if (!$info){
            $this->ajaxReturn(0, '数据不存在');
        }
        $status = $info['status'] == 1 ? 2 : 1;
        $tA = $this->mCategory->saveCustom(array('status' => $status), $id);
        if (!$tA){
            $this->ajaxReturn(0, '保存失败');
        }
        $this->ajaxReturn(1, '保存成功');
    }

/*********************************************商品列表*****************************************************************/

    /**
     * 获取商品列表
     * @author heyu
     */
    public function getProductList(){
        $id = get('merchant_id');
        $this->loadModel('ConsumerProductModel', 'mProduct', 'consumer');
        $data = $this->mProduct->adminGetList();
        foreach ($data['data'] as $k=>$v){
            $data['aaData'][$k][] = '<img src="'.getImage($v['icon'],'xs').'" class="img-wh" />';
            $data['aaData'][$k][] = $v['name'];
            $data['aaData'][$k][] = $v['cat_name'];
            $data['aaData'][$k][] = $v['is_limited'] == 1 ? '有限库存' : '无限库存';
            $data['aaData'][$k][] = $v['goods_price'].'/'.$v['goods_price'];
            $data['aaData'][$k][] = $v['sale_quantity'];
            $data['aaData'][$k][] = $v['quantity'];
            $data['aaData'][$k][] = dateFormat($v['addtime']);
            if ($v['status'] > 0){
                $status = $v['status'] == 1?2:1;
                $data['aaData'][$k][] = "<a href='".getUrl('product/home/changeStatus').'?id='.$v['id'].
                    "' class='ajax-request-btn deco' alert-message='是否确认".$this->mProduct->getStatus($status)."'>".
                    $this->mProduct->getStatus($v['status'],true)."</a>";
            }else{
                $data['aaData'][$k][] = $this->mProduct->getStatus($v['status'],true);
            }

            $btnConfig = adminCreateBtn(
                array(
                    'label' => '详情',
                    'attr' => array(
                        'href' => getUrl('merchant/productDetails?id='.$v['id']),
                        'class' => 'btn btn-xs green-stripe default'
                    ),
                    'tag' => 'a'
                ));
            $btnConfig .= ' '.adminCreateBtn(array(
                    'label' => '编辑',
                    'attr' => array(
                        'href' => getUrl('merchant/productForm?id='.$v['id'].'&merchant_id='.$id),
                        'class' => 'btn btn-xs blue-stripe default'
                    ),
                    'tag' => 'a',
                ));
            if ($v['status'] == 0 || $v['status'] == 1) {
                $btnConfig .= ' ' . adminCreateBtn(array(
                        'label' => '删除',
                        'attr' => array(
                            'href' => getUrl('product/home/deleteProduct?id=' . $v['id']),
                            'class' => 'btn btn-xs red-stripe default ajax-request-btn',
                            'alert-message' => '是否确定刪除 “ ' . $v['name'] . ' ” ?'
                        ),
                        'tag' => 'a',
                        'permissions' => array(
                            'module' => 'classes',
                            'key' => 'edit'
                        )
                    ));
            }
            $data['aaData'][$k][] = $btnConfig;
        }

        unset($data['data']);
        echo json_encode($data);
    }

    /**
     * 商品详情
     * @author heyu
     */
    public function productDetails(){
        $this->loadModel('ConsumerProductModel', 'mProduct', 'consumer');
        $this->loadModel('ConsumerCategoryModel', 'mCategory', 'consumer');
        $id = get('id');
        $tProduct = $this->mProduct->getInfo($id);
        if (! $tProduct){
            show_404();
        }
        $data = array(
            'backUrl' => getUrl('merchant/details').'?id='.$tProduct['merchant_id'],
            'title'=>'商品详情',
            'info'=>$tProduct,
            'merchant'=>$this->mMerchant->getInfo($tProduct['merchant_id']),
            'category'=>$this->mCategory->getCustomInfo($tProduct['category_id']),
        );

        $this->view('product/home/details', $data, 'datatable,select2,validation,datepicker,uniform');
    }

    /**
     * 商品编辑
     * @author heyu
     */
    public function productForm(){
       $this->loadModel('ConsumerProductModel', 'mProduct', 'consumer');
        $this->loadModel('ConsumerCategoryModel', 'mCategory', 'consumer');

        $id = get('id');
        $merchantId = (int)get('merchant_id');
        //获取商家信息
        $tMerchant = $this->mMerchant->getInfo($merchantId);

        if ($id){
            $tProduct = $this->mProduct->getInfo($id);
            if (! $tProduct){
                show_404();
            }
            $add = false;
        }else{
            $tProduct = array(
                'merchant_id' => $tMerchant['id'],
                'category_id' => 0,
                'is_limited' => 1,
            );
            $add = true;
        }
        //获取商家分类
        $tCategory = $this->mCategory->getCustomList($merchantId);
        //获取产品规格
        $tProperty = $this->mProduct->getPropertyList($id);
        //获取产品详情
        $tDetail  = $this->mProduct->getDetailList($id);
         $data = array(
             'title'=>'编辑商品',
             'info'=>$tProduct,
             'merchant'=>$tMerchant,
             'category'=>$tCategory,
             'property'=>$tProperty,
             'detail'=>$tDetail,
             'add'=> $add,
             'changeMerchant' => false,
             'backUrl' => getUrl('merchant/details').'?id='.$merchantId,
         );

         $this->view('product/home/form', $data, 'fileinput,uniform,webuploader,datatable,select2,validation,dropify');
    }

/*********************************************广告投放*****************************************************************/

    /**
     * 广告投放
     */
    public function getAdsList(){
        $id = get('merchant_id');
        if (!$id){
            $this->ajaxReturn(0, '数据错误');
        }
        $this->loadModel('MerchantAdsModel', 'mAds', 'merchant');
        $data = $this->mAds->adminPcGetList($id);
        $position = getCustomConfig('merchant_position');
        foreach ($data['data'] as $k=>$v){
            $data['aaData'][$k][] = $position[$v['ad_position']];
            $data['aaData'][$k][] = $v['day'];
            $data['aaData'][$k][] = date('Y-m-d H:i:s',$v['addtime']);
            if ($v['status'] == 4){
                $data['aaData'][$k][] = '<a href="#" class="popovers" data-placement="left" data-trigger="hover" data-content="'.
                    $v['note'].'" data-original-title="拒绝原因">'.$this->mAds->getStatus($v['status'], true).'</a>';
            }else{
                $data['aaData'][$k][] = $this->mAds->getStatus($v['status'], true);
            }

            if ($v['status'] == 1) {
                $btnConfig = adminCreateBtn(array(
                    'label' => ' 上传广告',
                    'attr' => array(
                        'href' => getUrl('config/ads/add') . '?merchant=' . $v['id'],
                        'class' => 'btn btn-xs blue-stripe default',
                    ),
                    'tag' => 'a',
                ));

                $btnConfig .= ' '.adminCreateBtn(array(
                        'label' => ' 拒绝',
                        'attr' => array(
                            'href' => 'javascript:;',
                            'class' => 'btn btn-xs red-stripe default refuse',
                            'data-id' => $v['id'],
                            'data-nickname' => $v['shop_name'],
                        ),
                        'tag' => 'a',
                    ));
                $data['aaData'][$k][] = $btnConfig;
            }else{
                $data['aaData'][$k][] = '';
            }
        }

        unset($data['data']);
        echo json_encode($data);
    }

    /**
     * 获取状态显示样式
     * @param 	integer $status
     * @return	string
     */
    private function _bonusStatus($status = null){

        $config = array(1 => '已结束', 2 => '未开始', 3 =>'进行中');
        if( ! $status){
            return '';
        }

        if($status == 1){
            return '<span class="label label-danger">'.$config[$status].'</span>';
        }else if($status == 2){
            return '<span class="label label-success">'.$config[$status].'</span>';
        }else if($status == 3){
            return '<span class="label label-warning">'.$config[$status].'</span>';
        }

        return'';
    }
}
